

/*
 * 获取子件数据
 */
function calFormItem() {
	var domForm = $('#' + window.formObj.c.id_form);
	var purchaseOrderBid = domForm.find('input[name="purchaseOrderBid"]').val(); // 采购完成单号
	var isRefund = domForm.find('select[name="isRefund"]').val(); // 是否退货

	$.ajax({
		type: "POST",
		url: '/api/inter/tcgPurchaseOrderWc/listItemByBid',
		data: {bid: purchaseOrderBid},
		success: function (data) {
			if (data.code == 0) {
				var rows = data.data;
				calculateData(rows,isRefund)
			} else {
				alert(data.msg);
			}
		}
	});

	return;
}

/*
 * 自动计算表单数据
 */
function calculateData(rows,isRefund) {
	for (var i = 0; i < rows.length; i++) {
		if (isRefund == '0') {
			rows[i]['subStorageNum'] = 0; // 子件库存数量
			rows[i]['subRefundNum'] = 0; // 子件退货数量
			rows[i]['subRefundPrice'] = 0; // 子件退货单价
		}else {
			rows[i]['subRefundNum'] = 0; // 子件退货数量
			if (rows[i]['subStorageNum'] == null || rows[i]['subStorageNum'] == undefined){
				rows[i]['subStorageNum'] = 0;
			}
			// rows[i]['offsetAmountNoTax'] = Math.round(rows[i]['offsetAmount'] / (1 + taxPercent) * 100) / 100; // 子件总额(不含税)
		}
	}

	formObj.c.subGridObj.clearRows();
	formObj.c.subGridObj.addRows(rows);
	return;
}

function  pData() {
	var domForm = $('#' + window.formObj.c.id_form);
	//拆装数量
	var refundAmount = domForm.find('input[name="refundAmount"]').val();
	var orderAmount = domForm.find('input[name="orderAmount"]').val();
	var refundServiceCharge = domForm.find('input[name="refundServiceCharge"]').val();
	var serviceCharge = domForm.find('input[name="serviceCharge"]').val();
	if(refundAmount){
		if(parseFloat(refundAmount)>parseFloat(orderAmount)){
			layer.msg("退款总额 应该小于等于 实际订单金额（含运）!");
			refundAmount = orderAmount;
			domForm.find('input[name="refundAmount"]').val(refundAmount);
		}
	}
	if(refundServiceCharge){
		if(parseFloat(refundServiceCharge)>parseFloat(serviceCharge)){
			layer.msg("采购服务费(退回) 应该小于等于 采购服务费!");
			refundServiceCharge = serviceCharge;
			domForm.find('input[name="refundServiceCharge"]').val(refundServiceCharge);
		}
	}
}